import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * Created by guo on 2017/11/9.
 */
public class CalculatorFee {

    /**
     * 将金额缩小rate倍变为分
     * @param fee
     * @param rate
     * @return
     */
    public static Integer calculate_to_fen(BigInteger fee,Integer rate){
        BigDecimal bd1 = new BigDecimal(fee);
        BigDecimal bd2 = new BigDecimal(rate);
        BigDecimal result = bd1.divide(bd2,0,BigDecimal.ROUND_HALF_UP);
        if (result.intValue()>Integer.MAX_VALUE){
            new Throwable();
        }
        return result.intValue();
    }

    /**
     * 将元转换为分
     * @param fee
     * @return
     */
    public static Integer cal_yun_to_fen(String fee){
        if (fee == null){
            return 0;
        }
        Double d = Double.parseDouble(fee);
        BigDecimal b = BigDecimal.valueOf(d);
        BigDecimal result = b.multiply(BigDecimal.valueOf(100));
        return result.intValue();
    }

    /**
     * 根据传入的数据计算出四舍五入的金额结果结果分
     * @param rate 缩小的倍数
     * @param args 传入的参数
     * @return
     */
    public static Integer cal_fee(Integer rate,Integer... args){
        Integer result = null;
        if (args != null && args.length > 0){
            for (Integer m : args){
                result = result*m;
            }
            return calculate_to_fen(BigInteger.valueOf(result),rate);
        }
        return 0;
    }

    public static void main(String[] args){
        //System.out.println(CalculatorFee.calculate_to_fen(BigInteger.valueOf(2312351),100));
        System.out.println(CalculatorFee.cal_yun_to_fen("64.09"));
    }
}
